/*
 * This file is part of the <a href="http://code.google.com/p/pux">PUX Framework</a>
 *
 * Copyright 2008 by <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package de.teamskill.pux.samples.xml;

import java.util.logging.Level;

import de.teamskill.pux.engine.Network;
import de.teamskill.pux.engine.AbstractNode;
import de.teamskill.pux.library.util.PrintNode;
import de.teamskill.pux.library.xml.LoadDocumentNode;
import de.teamskill.pux.library.xml.XPathNode;

/**
 * @author <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 */
public class XMLProcessingTest1 extends Network {

	/**
	 * XMLProcessingTest1 Constructor
	 * 
	 */
	public XMLProcessingTest1() {
		super();
	}

	/**
	 * setup
	 * 
	 */
	public void setup() {
		LOG_NET.setLevel(Level.ALL);
		LOG_NODE.setLevel(Level.ALL);
		LOG_PORT.setLevel(Level.ALL);

		AbstractNode load = new LoadDocumentNode().addToNetwork(this).makeStartupNode();
		load.configure(LoadDocumentNode.CONFIG_SOURCE, getClass().getResourceAsStream("sample1.xml"));

		AbstractNode path = new XPathNode().addToNetwork(this);
		path.configure(XPathNode.CONFIG_XPATH, "/sample/group/item[@id='i1']/text()");

		AbstractNode print = new PrintNode().addToNetwork(this);

		connect(load.getOutputPort(), path.getInputPort());
		connect(path.getOutputPort(), print.getInputPort());
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		XMLProcessingTest1 n = new XMLProcessingTest1();
		n.setup();
		n.start();
	}

}
